﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entity;
using DataAccess;

namespace Controller
{
    public class StockOutController:ControllerBase
    {
        public int addStockOut(string stockOutNo, int custId, DateTime date)
        {
            stockOutNo = stockOutNo.Trim();
            var count = (from stockOut in Sdc.StockOuts
                         where stockOut.No == stockOutNo
                         select stockOut).Count();
            if(count<=0)
            {
                StockOut stockOut = new StockOut();
                stockOut.No = stockOutNo;
                stockOut.CustId = custId;
                stockOut.Date = date;
                stockOut.Remark = "";
                Sdc.StockOuts.InsertOnSubmit(stockOut);
                Sdc.SubmitChanges();
                return stockOut.Id;
            }
            else
            {
                return -1;
            }
            
        }
    }
}
